package pack

import (
	"mall_admin_api/biz/model"
	"mall_admin_api/biz/model/admin_user"
)

func GetUserName(user *model.User) string {
	if user == nil {
		return ""
	}
	if user.FirstName == "" {
		return user.LastName
	}
	if user.LastName == "" {
		return user.FirstName
	}
	return user.FirstName + "·" + user.LastName
}

func GetUserList(list []*model.User) []*admin_user.User {
	var data = make([]*admin_user.User, 0)
	if len(list) == 0 {
		return data
	}
	for _, category := range list {
		if category != nil {
			data = append(data, User(category))
		}
	}
	return data
}

func User(data *model.User) *admin_user.User {
	info := &admin_user.User{
		ID:     data.ID,
		Name:   GetUserName(data),
		Email:  data.Email,
		Avatar: data.Avatar,
		Points: data.Points,
	}

	if !data.LastLoginTime.IsZero() {
		info.LastLoginTime = data.LastLoginTime.UnixMilli()
	}
	return info
}
